package copyengine.ui.font
{
	import flash.text.AntiAliasType;
	import flash.text.TextField;
	import flash.text.TextFormat;

	public final class FontEmbedManger
	{
		private static var _instance:FontEmbedManger;

		public static function get instance():FontEmbedManger
		{
			if (_instance == null)
			{
				_instance = new FontEmbedManger();
			}
			return _instance;
		}

		private var fontEmbedQuery:IFontEmbedQuery;
		private var languageLocal:String;

		public function FontEmbedManger()
		{
		}

		public function initialize(_fontEmbedQuery:IFontEmbedQuery):void
		{
			fontEmbedQuery = _fontEmbedQuery;
		}

		public function setLanguageLocal(_local:String):void
		{
			languageLocal = _local;
		}

		public function getNeedEmbedFontNameArray():Array
		{
			return fontEmbedQuery.getFontEmbedFileNameByLanguageLocal(languageLocal);
		}

		public function embedTextField(_textField:TextField):void
		{
			if (_textField != null)
			{
				var format:TextFormat = _textField.getTextFormat();
				if (fontEmbedQuery.isCanEmbedFont(languageLocal, format.font))
				{
					_textField.embedFonts = true;

					_textField.antiAliasType = AntiAliasType.ADVANCED;
					format.font = fontEmbedQuery.getEmbedNameByOriginalName(languageLocal, format.font);
					_textField.defaultTextFormat = format;
					_textField.setTextFormat(format);
				}
			}
		}
	}
}